/**
 * 
 */
package com.xb.concurrent.blockqueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author kexue
 *
 */
public class TestMainLockCondition {

	private static Logger logger = LoggerFactory.getLogger(TestMainLockCondition.class);
	public static void main(String[] args) throws InterruptedException {
		
		final BlockBufferLockCondition buffer=new BlockBufferLockCondition();
		Thread produce1 = createProduce(buffer);
		//Thread produce2 = createProduce(buffer);
		Thread consume1 = createConsume(buffer);
		

		produce1.start();
		//produce2.start();
		consume1.start();
 
		
	}
	/**
	 * @param buffer
	 * @return
	 */
	private static Thread createProduce(final BlockBufferLockCondition buffer) {
		return new Thread(new Runnable() {
			public void run() {
				for(int i=0;i<10000;i++){
					try {
						buffer.put(i+"");
						
						float rs=12.0f; 
						for(int j=0;j<1000*1000;j++){
							rs=rs*j;
						}
						logger.info("put:"+i);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
	}
	/**
	 * @param buffer
	 * @return
	 */
	private static Thread createConsume(final BlockBufferLockCondition buffer) {
		return new Thread(new Runnable() {
			public void run() {
				for(int i=0;i<100;i++){
					try {
						Object take = buffer.take();
						logger.info("take:"+take);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
	}
}
